class @AdminUserCreateView extends CustomView
    el:$('#content')

    initialize: ->
        super

    render:->
        model = @model
        el = $(@el)

        @GetTemplate(SiteMap.Admin.Users.CreateTemplate, (compiledTemplate) ->
            el.html(compiledTemplate(model.toJSON()))

            $("#Status").combobox()
            $("#Avatar").ImageUpload()
        )

    events:
        "click .buttons>button.save": "save",
        "click .buttons>button.cancel": "cancel"

    save: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.WriteMessage('Creating user.')

        data = $(@el).find("form.general").serialize()

        $.post(SiteMap.Admin.Users.Create, data, (response) =>
            if (response.SuccessMessage? && response.SuccessMessage.length)
                Messages.WriteSuccessMessage(response.SuccessMessage)
                @Navigate(SiteMap.Admin.Users.Listing, true)
            else
                Messages.WriteErrors(response.Errors)
                Loading.Stop()
        )

    cancel: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.Clear()
        @Navigate(SiteMap.Admin.Users.Listing, true)